﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Website
{
    public partial class FilmPagina : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Film film = (Film)Session["film"];
            Label_Title.Text = film.naam;
            Label_Description.Text = film.omschrijving;
            Trailer.Text = "<iframe title=" + (char)34 + "YouTube video player" + (char)34 + " width=" + (char)34 + "675" + (char)34 + " height=" + (char)34 + "438" + (char)34 + " src=" + (char)34 + film.trailer.Trim() + (char)34 + " frameborder=" + (char)34 + "0" + (char)34 + " allowfullscreen></iframe>";

            String imagefile = "leeftijd_al_klein.png";

            switch (film.minimaleleeftijd.ToString())
            {
                case "6":
                    imagefile = "leeftijd_6_klein.png";
                    break;
                case "9":
                    imagefile = "leeftijd_9_klein.png";
                    break;
                case "12":
                    imagefile = "leeftijd_12_klein.png";
                    break;
                case "16":
                    imagefile = "leeftijd_16_klein.png";;
                    break;
            }

            Image_Age.ImageUrl = Module.IMAGE_FOLDER + imagefile;
            if (film.pauze) { Image_Break.ImageUrl = Module.IMAGE_FOLDER + "pauze.png"; }
            if (film._3d) { Image_DrieD.ImageUrl = Module.IMAGE_FOLDER + "3d.png"; }

            FilmPosterInfo filmPosterInfo = (FilmPosterInfo)LoadControl("FilmPosterInfo.ascx");
            filmPosterInfo.setgetFilm = film;
            Panel_FilmPosterInfo.Controls.Add(filmPosterInfo);

            var voorstellingen = from v in Module.database.Voorstellings
                                 where v.Film == film && v.datumtijd >= DateTime.Now
                                 orderby v.datumtijd ascending
                                 select v;

            if (voorstellingen.Count() > 0)
            {
                DateTime currentDateTime = voorstellingen.First().datumtijd;
                TableRow currentRow = new TableRow();
                TableCell currentCell_Shows = new TableCell();
                TableCell currentCell_Date = new TableCell();

                Label label = new Label();
                label.CssClass = "datumprofiel";
                if (DateTime.Now.ToString("MM dd") == currentDateTime.ToString("MM dd"))
                {
                    label.Text = "Vandaag";
                }
                else if (DateTime.Now.AddDays(1).ToString("MM dd") == currentDateTime.ToString("MM dd"))
                {
                    label.Text = "Morgen";
                }
                else
                {
                    label.Text = currentDateTime.ToString("dd ");
                    if (currentDateTime.ToString("MM") == "01")
                    {

                    }
                    else if (currentDateTime.ToString("MM") == "01")
                    {
                        label.Text += "Januari";
                    }
                    else if (currentDateTime.ToString("MM") == "02")
                    {
                        label.Text += "Februari";
                    }
                    else if (currentDateTime.ToString("MM") == "03")
                    {
                        label.Text += "Maart";
                    }
                    else if (currentDateTime.ToString("MM") == "04")
                    {
                        label.Text += "April";
                    }
                    else if (currentDateTime.ToString("MM") == "05")
                    {
                        label.Text += "Mei";
                    }
                    else if (currentDateTime.ToString("MM") == "06")
                    {
                        label.Text += "Juni";
                    }
                    else if (currentDateTime.ToString("MM") == "07")
                    {
                        label.Text += "Juli";
                    }
                    else if (currentDateTime.ToString("MM") == "08")
                    {
                        label.Text += "Augustus";
                    }
                    else if (currentDateTime.ToString("MM") == "09")
                    {
                        label.Text += "September";
                    }
                    else if (currentDateTime.ToString("MM") == "10")
                    {
                        label.Text += "Oktober";
                    }
                    else if (currentDateTime.ToString("MM") == "11")
                    {
                        label.Text += "November";
                    }
                    else if (currentDateTime.ToString("MM") == "12")
                    {
                        label.Text += "December";
                    }
                }

                currentCell_Date.Controls.Add(label);

                currentRow.Cells.Add(currentCell_Date);

                foreach (var v in voorstellingen)
                {
                    if (currentDateTime.Date.CompareTo(v.datumtijd.Date) != 0)
                    {
                        currentRow.Cells.Add(currentCell_Shows);
                        Table_Voorstellingen.Rows.Add(currentRow);

                        currentDateTime = v.datumtijd;
                        currentRow = new TableRow();
                        currentCell_Shows = new TableCell();
                        currentCell_Date = new TableCell();

                        Label label_date = new Label();
                        label_date.CssClass = "datumprofiel";

                        if (DateTime.Now.ToString("MM dd") == v.datumtijd.ToString("MM dd"))
                        {
                            label_date.Text = "Vandaag";
                        }
                        else if (DateTime.Now.AddDays(1).ToString("MM dd") == v.datumtijd.ToString("MM dd"))
                        {
                            label_date.Text = "Morgen";
                        }
                        else
                        {

                            label_date.Text = v.datumtijd.ToString("dd ");
                            if (v.datumtijd.ToString("MM") == "01")
                            {

                            }
                            else if (v.datumtijd.ToString("MM") == "01")
                            {
                                label_date.Text += "Januari";
                            }
                            else if (v.datumtijd.ToString("MM") == "02")
                            {
                                label_date.Text += "Februari";
                            }
                            else if (v.datumtijd.ToString("MM") == "03")
                            {
                                label_date.Text += "Maart";
                            }
                            else if (v.datumtijd.ToString("MM") == "04")
                            {
                                label_date.Text += "April";
                            }
                            else if (v.datumtijd.ToString("MM") == "05")
                            {
                                label_date.Text += "Mei";
                            }
                            else if (v.datumtijd.ToString("MM") == "06")
                            {
                                label_date.Text += "Juni";
                            }
                            else if (v.datumtijd.ToString("MM") == "07")
                            {
                                label_date.Text += "Juli";
                            }
                            else if (v.datumtijd.ToString("MM") == "08")
                            {
                                label_date.Text += "Augustus";
                            }
                            else if (v.datumtijd.ToString("MM") == "09")
                            {
                                label_date.Text += "September";
                            }
                            else if (v.datumtijd.ToString("MM") == "10")
                            {
                                label_date.Text += "Oktober";
                            }
                            else if (v.datumtijd.ToString("MM") == "11")
                            {
                                label_date.Text += "November";
                            }
                            else if (v.datumtijd.ToString("MM") == "12")
                            {
                                label_date.Text += "December";
                            }
                        }
                        currentCell_Date.Controls.Add(label_date);

                        currentRow.Cells.Add(currentCell_Date);
                    }

                    VoorstellingButton button = (VoorstellingButton)LoadControl("VoorstellingButton.ascx");
                    button.getsetVoorstelling = v;
                    currentCell_Shows.Controls.Add(button);
                }

                currentRow.Cells.Add(currentCell_Shows);
                Table_Voorstellingen.Rows.Add(currentRow);
            }
        }
    }
}